Ext.onReady(function(){ 

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'under';

var addCurrencyStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=Currency',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) ,
autoLoad:true
}); 

var debtQualityStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=DebtQuality',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) 
,
autoLoad:true
}); 

var addGuarantyKindStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=GuarantyKind',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) ,
autoLoad:true
}); 

var addDebtTypeStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=DebtType',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) ,
autoLoad:true
}); 


//客户基本信息
var addForm = new Ext.form.FormPanel({ 
id: 'addForm', 
title: '债项评级', 
renderTo:"list",
height: 270, 
//样式 
bodyStyle: 'margin:5px;text-align:left;padding:5px 60px;', 
frame: true, 
xtype: 'filedset', 
labelWidth: 100, 
items: 
[ { xtype: 'fieldset', 
collapsible: true, 
autoHeight: true, 
autoWidth: true, 
items: 
[
	
{layout : "form",
	items : [	{ 
				xtype: 'textfield', 
			id:'debtNo',
			name: 'debtNo', 
			fieldLabel: '债项流水号', 
			readOnly:true,
			width: 200,
			hidden:true
	}]},
	
	{layout : "form",
		items : [	{ 
					xtype: 'textfield', 
				id:'debtId',
				name: 'debtId', 
				fieldLabel: '债项编号', 
				readOnly:true,
				width: 200
		}]},
	
{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
		xtype: 'textfield', 
			id:'debtDesc',
			name: 'debtDesc', 
			fieldLabel: '债项名称', 
			emptyText: '必填', 
			blankText: '债项名称不能为空', 
			allowBlank: false, 
			readOnly:true,
			width: 200
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
			xtype: 'combo', 
			 	id : "debtType",
              store :addDebtTypeStore,
              fieldLabel: '债项业务品种',
              valueField : 'code',
              displayField : 'name',
              typeAhead : true,
              width: 200,
              readOnly:true,
              mode:'remote', 
              editable: false,
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'debtType'
}
]} 
]},{
layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
					xtype: 'combo', 
 			id : "currency",
              store :addCurrencyStore,
              fieldLabel: '债项币种',
              valueField : 'code',
              displayField : 'name',
              typeAhead : true,
              width: 200,
              readOnly:true,
              mode:'remote', 
              editable: false,
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'currency'
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
			xtype: 'textfield', 
				id: 'debtSum',
				name: 'debtSum', 
				fieldLabel: '合同金额(元)', 
				emptyText: '必填', 
				readOnly:true,
				blankText: '债项金额不能为空', 
				allowBlank: false,  
				regex:  /^[0-9]+(.[0-9]{1,9})?$/,
			 	regexText:'只能输入整数或小数！' , 
				width: 200
}
]} 
]},
{
layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
        	   xtype: 'textfield', 
				id: 'debtBalance',
				name: 'debtBalance', 
				fieldLabel: '债项余额(元)', 
				emptyText: '必填', 
				blankText: '债项余额不能为空', 
				allowBlank: false,  
				regex:/^[0-9]+\.{0,1}[0-9]{0,9}$/,
			 	regexText:'只能输入整数或小数！' , 
				width: 200
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
           xtype: 'datefield',
id: 'startDate', 
name: 'startDate', 
fieldLabel: '起始日',
allowBlank: true,
editable:false,  
format : 'Y-m-d' ,
readOnly:true,
width: 200
}
]} 
]},

{
layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
        	   xtype: 'combo', 
				 id : "debtQuality",
	              store :debtQualityStore,
	              fieldLabel: '债项性质',
	              valueField : 'code',
	              displayField : 'name',
	              typeAhead : true,
	              width: 200,
	              allowBlank : true,
	              mode:'remote', 
	              editable: false,
	              triggerAction : 'all',
	              selectOnFocus : true,
	              hiddenName:'debtQuality' 
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
        	   
			xtype: 'datefield',
			id: 'endDate', 
			name: 'endDate', 
			fieldLabel: '到期日',
			allowBlank: true,
			editable:false,  
			readOnly:true,
			format : 'Y-m-d' ,
			width: 200
}
]} 
]},

{
layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
                  xtype: 'combo', 
 id : "guarantyKind",
              store :addGuarantyKindStore,
            fieldLabel: '担保类型',
              valueField : 'code',
              displayField : 'name',
              editable: false,
              typeAhead : true,
              width: 200,
              readOnly:true,
              mode:'remote',  
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'guarantyKind'
}
]}

]},

] 
}],
buttonAlign:'right',
buttons: 
[  
{ text: '计算', handler:calculateDebtRating } 
],
});


function calculateDebtRating(){
	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
		url : 'rating/calculateDebtRating.do', 
		method : 'post', 
		success : function(form, action) { 
			//Ext.Msg.alert('提示', action.result.data.lgd); 
			Ext.getCmp("lgd").setValue(action.result.data.lgd);
			Ext.getCmp("ead").setValue(action.result.data.ead);
		}, 
		failure : function(form, action) { 
			Ext.Msg.alert('提示', '计算失败！'); 
		} 
		});  
	}	
}


//结果表单
resultForm = new Ext.form.FormPanel({ 
id: 'resultForm', 
height: 150,
renderTo:"result",
//样式 
bodyStyle: 'margin:5px;text-align:left;padding:5px 60px;', 
frame: true, 
xtype: 'filedset', 
labelWidth: 100, 
items: 
[ { xtype: 'fieldset', 
title: '计算结果', 
collapsible: true, 
autoHeight: true, 
autoWidth: true, 
items: 
[ 
{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield', 
	id:'lgd',
	name: 'lgd', 
	fieldLabel: '违约损失率LGD(%)', 
	readOnly:true,
	width: 200
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield', 
	id:'ead',
	name: 'ead', 
	fieldLabel: '违约风险暴露EAD(元)', 
	readOnly:true,
	width: 200
}
]} 
]},
] 
}]

,
buttonAlign:'right',
buttons: 
[  
{ text: '保存', handler:saveDebtRating },
{ text: '返回', handler:returnDebtRating }
],

});

//表单加载数据
addForm.form.load({  
    waitMsg : '正在加载数据请稍后',
    waitTitle : '提示',
    url : 'rating/getDebt.do', 
    method:'post',
    success:function(form,action){
    	Ext.getCmp("lgd").setValue(action.result.data.lgd);
		Ext.getCmp("ead").setValue(action.result.data.ead);
    },  
    failure:function(form,action){
     Ext.Msg.alert('提示','数据加载失败');  
    }  
});


function returnDebtRating(){
	window.location.href = 'view/rating/DebtRating_DebtList.jsp';
}

function saveDebtRating(){
	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
		url : 'rating/saveDebtRating.do', 
		method : 'post', 
		success : function(form, action) {  
	    	Ext.getCmp("lgd").setValue(action.result.data.lgd);
			Ext.getCmp("ead").setValue(action.result.data.ead);
				Ext.Msg.alert('提示', '保存成功！');
		}, 
		failure : function(form, action) { 
			Ext.Msg.alert('提示', '保存失败！'); 
		} 
		});  
	}
}
       
}); 